﻿using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Game;
using NetProtocol.POD;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IQIGame.Onigao.Logic
{
    public class BattlePlayer : IReusableClass
    {
        public long id; // id需要冗余存储
        public Battle battle { get; private set; }
        
        public ISession session; // enterBattle以后再赋值，避免提前被广播协议
        public LogicPlayer logicPlayer { get; private set; } // 玩家连接之后才有数据

        #region 战斗内数据

        public string name { get; private set; }
        public bool isReadyToStart { get; set; } = false;

        #endregion

        public uint MaxStore => 2;

        public void InitId(long pid, Battle battle)
        {
            this.id = pid;
            this.battle = battle;
        }

        /// <summary>
        /// 在玩家连接成功时调用
        /// </summary>
        /// <param name="logicPlayer"></param>
        public void SetLogicPlayer(LogicPlayer logicPlayer)
        {
            this.logicPlayer = logicPlayer;
            logicPlayer.battlePlayer = this;
            // 初始化默认值，运行时可能被修改
            this.name = logicPlayer.name;
        }

        public void OnReset()
        {
            id = 0;
            session = null;
            battle = null;
            
            if (logicPlayer!= null)
            {
                logicPlayer.battlePlayer = null;
            }
            logicPlayer = null;

            name = null;
            isReadyToStart = false;
        }
    }
}